package com.devouty.mp3online.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.devouty.mp3online.R;
import com.devouty.mp3online.bean.Music;

import java.util.List;

/**
 * Created by devouty on 15年7月31日.
 */
public class MusicListViewMainAdapter extends BaseAdapter {

    private List<Music> mData;

    private Context mContext;
    private LayoutInflater mInflater;
    public MusicListViewMainAdapter(List<Music> musics, Context context){
        this.mData = musics;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return mData == null ? 0:mData.size();
    }

    @Override
    public Object getItem(int location) {
        return mData == null?null:mData.get(location);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    class Holder{
        TextView singer;
        TextView title;
    }
    @Override
    public View getView(int position, View coverView, ViewGroup parent) {
        Holder holder;
        if(coverView ==null)
        {
            coverView = mInflater.inflate(R.layout.list_item, null);
            holder = new Holder();
            holder.singer = (TextView)coverView.findViewById(R.id.txtv_main_list_item_singer);
            holder.title = (TextView) coverView.findViewById(R.id.txtv_main_list_item_title);

            coverView.setTag(holder);

        }else{
            holder = (Holder) coverView.getTag();
        }
        holder.title.setText(mData.get(position).getTitle());
        holder.singer.setText(mData.get(position).getSinger());

        return coverView;
    }
}
